package ar.edu.utn.frsf.tpae.a2013.g03.presentacion.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import ar.edu.utn.frsf.tpae.a2013.g03.service.EmpleadoService;
import ar.edu.utn.frsf.tpae.a2013.g03.service.SupervisorService;

/**
 * Clase de utilidad que provee acceso a instancias administradas por Spring.
 * 
 * @author DFJ
 */
public class ServiceLocator {

	private static ApplicationContext context;

	private static ApplicationContext getContext() {
		if (context == null) {
			synchronized (ServiceLocator.class) {
				if (context == null) {
					context = new ClassPathXmlApplicationContext(
							"classpath*:**/application-context-presentacion.xml");
				}
			}
		}
		return context;
	}

	public static SupervisorService getSupervisorService() {
		return (SupervisorService) getContext().getBean("supervisorService");
	}
	
	public static EmpleadoService getEmpleadoService() {
		return (EmpleadoService) getContext().getBean("empleadoService");
	}

}
